package me.shurufa.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.implement.ItemClickListener;
import me.shurufa.model.Book;


/**
 *
 *
 * @FileName: me.khrystal.holder.SingleChooseViewHolder.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-02-15 10:11
 */
public class SingleChooseViewHolder extends BaseViewHolder{

    @Bind(R.id.item_content)
    ImageView itemContent;
    @Bind(R.id.item_check)
    RelativeLayout itemCheck;
    @Bind(R.id.item_root)
    RelativeLayout itemRoot;


    private Context mContext;
    private int mPosition;
    private Book mBook;
    private ItemClickListener mListener;


    public SingleChooseViewHolder(View itemView, Object parent, ItemClickListener listener) {
        super(itemView, parent);
        mContext = itemView.getContext();
        this.mListener = listener;
        ButterKnife.bind(this,itemView);
        addOnClickListener(itemRoot);
    }

    public void bind(Book book,boolean check,int position){
        this.mPosition = position;
        this.mBook = book;
        itemCheck.setVisibility(check ? View.VISIBLE : View.GONE);
        if (!TextUtils.isEmpty(book.image))
            Glide.with(mContext).load(book.image).into(itemContent);
        else {
            //TODO 设置默认图片
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.item_root:
                if (mListener!=null)
                    mListener.onItemClick(v,mBook,mPosition);
                break;
        }
    }
}
